using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQVW_QORDER
    {
        public DataRow Convert2QVW_QORDER(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryQVW_QORDER(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["QKAUF"] = " ".PadRight(9 ); 
         dwReturn["QNDATE"] = " ".PadRight(0 ); 
         dwReturn["QNYEAR"] = " ".PadRight(4 ); 
         dwReturn["QNMONTH"] = " ".PadRight(2 ); 
         dwReturn["QNDAY"] = " ".PadRight(2 ); 
         dwReturn["QNQUARTER"] = " ".PadRight(41 ); 
         dwReturn["QFDATE"] = " ".PadRight(0 ); 
         dwReturn["QFYEAR"] = " ".PadRight(4 ); 
         dwReturn["QFMONTH"] = " ".PadRight(2 ); 
         dwReturn["QFDAY"] = " ".PadRight(2 ); 
         dwReturn["QPLAN"] = " ".PadRight(8 ); 
         dwReturn["QOKDYNTAB"] = " ".PadRight(2 ); 
         dwReturn["QOKPRSFE"] = " ".PadRight(0 ); 
         dwReturn["QOKPREINHT"] = " ".PadRight(2 ); 
         dwReturn["ARTST"] = " ".PadRight(1 ); 
         dwReturn["PART"] = " ".PadRight(20 ); 
         dwReturn["PVAR"] = " ".PadRight(3 ); 
         dwReturn["PCOLOR"] = " ".PadRight(10 ); 
         dwReturn["PDESS"] = " ".PadRight(10 ); 
         dwReturn["PDCWY"] = " ".PadRight(10 ); 
         dwReturn["PFINISH"] = " ".PadRight(10 ); 
         dwReturn["PSIZE"] = " ".PadRight(7 ); 
         dwReturn["AUFTYP"] = " ".PadRight(1 ); 
         dwReturn["KAUF"] = " ".PadRight(9 ); 
         dwReturn["PAUF"] = " ".PadRight(12 ); 
         dwReturn["PKRS"] = " ".PadRight(2 ); 
         dwReturn["PLFD"] = " ".PadRight(6 ); 
         dwReturn["PPOS"] = " ".PadRight(3 ); 
         dwReturn["PFSTEP"] = " ".PadRight(3 ); 
         dwReturn["RESULT"] = " ".PadRight(1 ); 
         dwReturn["QOKTYPE"] = " ".PadRight(3 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapQVW_QORDER(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQVW_QORDER(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQVW_QORDER(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQVW_QORDER(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertQVW_QORDER(dwLocal, ITXDBVERSION);
            }
            UpdateQVW_QORDER(dwLocal);
        }
        public void InsertQVW_QORDER(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QVW_QORDER(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryQVW_QORDER(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QVW_QORDER WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM QVW_QORDER  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QVW_QORDER";
            Return = Result;
            return Return;
        }
        public void DeleteQVW_QORDER(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QVW_QORDER   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateQVW_QORDER(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE QVW_QORDER SET "
                    +"QKAUF= :QKAUF,"
                    +"QNDATE= :QNDATE,"
                    +"QNYEAR= :QNYEAR,"
                    +"QNMONTH= :QNMONTH,"
                    +"QNDAY= :QNDAY,"
                    +"QNQUARTER= :QNQUARTER,"
                    +"QFDATE= :QFDATE,"
                    +"QFYEAR= :QFYEAR,"
                    +"QFMONTH= :QFMONTH,"
                    +"QFDAY= :QFDAY,"
                    +"QPLAN= :QPLAN,"
                    +"QOKDYNTAB= :QOKDYNTAB,"
                    +"QOKPRSFE= :QOKPRSFE,"
                    +"QOKPREINHT= :QOKPREINHT,"
                    +"ARTST= :ARTST,"
                    +"PART= :PART,"
                    +"PVAR= :PVAR,"
                    +"PCOLOR= :PCOLOR,"
                    +"PDESS= :PDESS,"
                    +"PDCWY= :PDCWY,"
                    +"PFINISH= :PFINISH,"
                    +"PSIZE= :PSIZE,"
                    +"AUFTYP= :AUFTYP,"
                    +"KAUF= :KAUF,"
                    +"PAUF= :PAUF,"
                    +"PKRS= :PKRS,"
                    +"PLFD= :PLFD,"
                    +"PPOS= :PPOS,"
                    +"PFSTEP= :PFSTEP,"
                    +"RESULT= :RESULT,"
                    +"QOKTYPE= :QOKTYPE,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("QKAUF", OracleType.NVarChar).Value = dwData["QKAUF"].ToString(); 
          or1.Parameters.Add("QNDATE", OracleType.NVarChar).Value = dwData["QNDATE"].ToString(); 
          or1.Parameters.Add("QNYEAR", OracleType.NVarChar).Value = dwData["QNYEAR"].ToString(); 
          or1.Parameters.Add("QNMONTH", OracleType.NVarChar).Value = dwData["QNMONTH"].ToString(); 
          or1.Parameters.Add("QNDAY", OracleType.NVarChar).Value = dwData["QNDAY"].ToString(); 
          or1.Parameters.Add("QNQUARTER", OracleType.NVarChar).Value = dwData["QNQUARTER"].ToString(); 
          or1.Parameters.Add("QFDATE", OracleType.NVarChar).Value = dwData["QFDATE"].ToString(); 
          or1.Parameters.Add("QFYEAR", OracleType.NVarChar).Value = dwData["QFYEAR"].ToString(); 
          or1.Parameters.Add("QFMONTH", OracleType.NVarChar).Value = dwData["QFMONTH"].ToString(); 
          or1.Parameters.Add("QFDAY", OracleType.NVarChar).Value = dwData["QFDAY"].ToString(); 
          or1.Parameters.Add("QPLAN", OracleType.NVarChar).Value = dwData["QPLAN"].ToString(); 
          or1.Parameters.Add("QOKDYNTAB", OracleType.NVarChar).Value = dwData["QOKDYNTAB"].ToString(); 
          or1.Parameters.Add("QOKPRSFE", OracleType.NVarChar).Value = dwData["QOKPRSFE"].ToString(); 
          or1.Parameters.Add("QOKPREINHT", OracleType.NVarChar).Value = dwData["QOKPREINHT"].ToString(); 
          or1.Parameters.Add("ARTST", OracleType.NVarChar).Value = dwData["ARTST"].ToString(); 
          or1.Parameters.Add("PART", OracleType.NVarChar).Value = dwData["PART"].ToString(); 
          or1.Parameters.Add("PVAR", OracleType.NVarChar).Value = dwData["PVAR"].ToString(); 
          or1.Parameters.Add("PCOLOR", OracleType.NVarChar).Value = dwData["PCOLOR"].ToString(); 
          or1.Parameters.Add("PDESS", OracleType.NVarChar).Value = dwData["PDESS"].ToString(); 
          or1.Parameters.Add("PDCWY", OracleType.NVarChar).Value = dwData["PDCWY"].ToString(); 
          or1.Parameters.Add("PFINISH", OracleType.NVarChar).Value = dwData["PFINISH"].ToString(); 
          or1.Parameters.Add("PSIZE", OracleType.NVarChar).Value = dwData["PSIZE"].ToString(); 
          or1.Parameters.Add("AUFTYP", OracleType.NVarChar).Value = dwData["AUFTYP"].ToString(); 
          or1.Parameters.Add("KAUF", OracleType.NVarChar).Value = dwData["KAUF"].ToString(); 
          or1.Parameters.Add("PAUF", OracleType.NVarChar).Value = dwData["PAUF"].ToString(); 
          or1.Parameters.Add("PKRS", OracleType.NVarChar).Value = dwData["PKRS"].ToString(); 
          or1.Parameters.Add("PLFD", OracleType.NVarChar).Value = dwData["PLFD"].ToString(); 
          or1.Parameters.Add("PPOS", OracleType.NVarChar).Value = dwData["PPOS"].ToString(); 
          or1.Parameters.Add("PFSTEP", OracleType.NVarChar).Value = dwData["PFSTEP"].ToString(); 
          or1.Parameters.Add("RESULT", OracleType.NVarChar).Value = dwData["RESULT"].ToString(); 
          or1.Parameters.Add("QOKTYPE", OracleType.NVarChar).Value = dwData["QOKTYPE"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
